//
//  ZCTextField.m
//  SSMusic
//
//  Created by 张灿 on 16/4/22.
//  Copyright © 2016年 张灿. All rights reserved.
//

#import "ZCTextField.h"
#import <UIView+SDAutoLayout.h>

@interface ZCTextField ()

@property (copy, nonatomic) NSString *placeHolder;

@end

@implementation ZCTextField

//懒加载
- (NSString *)placeHolder
{
    if (_placeHolder == nil) {
        _placeHolder = @"搜索音乐、歌词、电台";
    }
    return _placeHolder;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        //添加所有子控件
        [self setAllChildView];
        
        //设置显示模式
        [self setConfigV];
    }
    return self;
}

//设置样式
- (void)setConfigV
{
    //背景色
    self.backgroundColor = [UIColor whiteColor];
    
    //圆角
    self.layer.cornerRadius = 4;
    self.layer.masksToBounds = YES;
}

- (void)setAllChildView
{
    //创建放大镜小图片
    UIImageView *imageV = [[UIImageView alloc] init];
    imageV.image = [UIImage imageNamed:@"cm2_topbar_icn_search"];
    //添加到父控制器
    [self addSubview:imageV];
    
    //设置约束
    imageV.sd_layout.leftSpaceToView(self,50).topSpaceToView(self,10).bottomSpaceToView(self,10).widthEqualToHeight(12);
    
    
    //创建textfield
    UITextField *textField = [[UITextField alloc] init];
    textField.placeholder = self.placeHolder;
    textField.font = [UIFont systemFontOfSize:12];
    //添加到父控制器
    [self addSubview:textField];
    
    //设置约束
    textField.sd_layout.leftSpaceToView(imageV,5).topSpaceToView(self,0).bottomSpaceToView(self,0).rightSpaceToView(self,0);
    
}

@end
